package com.base.api.controller.selfAddress;

import com.base.api.dto.selfAddress.SelfAddressApiAddDTO;
import com.base.api.dto.selfAddress.SelfAddressApiDelDTO;
import com.base.api.dto.selfAddress.SelfAddressApiListDTO;
import com.base.api.service.selfAddress.SelfAddressApiService;
import com.base.log.WebLog;
import com.base.result.ResponseResult;
import com.base.self.entity.SelfAddress;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Slf4j
@RequestMapping("/api/selfAddress")
@Api(tags = "收货地址")
public class SelfAddressApiController {

    private final SelfAddressApiService selfAddressApiService;

    public SelfAddressApiController(SelfAddressApiService selfAddressApiService) {
        this.selfAddressApiService = selfAddressApiService;
    }

    @ApiOperation(value="收货地址列表查询")
    @PostMapping(value = "/selfAddressApiList", produces = "application/json;charset=UTF-8")
    @Validated
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = SelfAddress.class),
    })
    @WebLog
    public ResponseResult selfAddressApiList(final @Valid SelfAddressApiListDTO selfAddressApiListDTO){
        return selfAddressApiService.selfAddressApiList(selfAddressApiListDTO);
    }

    @ApiOperation(value="添加收货地址")
    @PostMapping(value = "/selfAddressApiAdd", produces = "application/json;charset=UTF-8")
    @Validated
    @WebLog
    public ResponseResult selfAddressApiAdd(final @Valid SelfAddressApiAddDTO selfAddressApiAddDTO){
        return selfAddressApiService.selfAddressApiAdd(selfAddressApiAddDTO);
    }

    @ApiOperation(value="删除收货地址")
    @PostMapping(value = "/selfAddressApiDel", produces = "application/json;charset=UTF-8")
    @Validated
    @WebLog
    public ResponseResult selfAddressApiDel(final @Valid SelfAddressApiDelDTO selfAddressApiDelDTO){
        return selfAddressApiService.selfAddressApiDel(selfAddressApiDelDTO);
    }
}
